/** 
 * Author:weishuheng
 * Time:2015-04-16
 * recruiter.js用于简历创建页面add.html调用插件和页面初始化
**/
;$(function(){
	// $('#hukou_selete').seleteCity({			//户口所在地 - 地区控件调用
	// 	isForeign:true,
	// 	isArea	: false,
	// 	closeCallback:callBack_hukou,
	// 	language:language
	// });
	// $('#hukou_pp').seleteCity({				//现居住城市 - 地区控件调用
	// 	isForeign:true,
	// 	closeCallback:callBack_City,
	// 	language:language
	// });
	$('#birth_date_y').DateLink({			//出生年月、年 - 时间控件调用
		close:callBack_dateY,
		languageId:language
	});
	$('#birth_date_m').DateLink({			//出生年月、月 - 时间控件调用
		IsYear:false,
		left:'-218px',
		divClass:'month_show',
		closeM: callBack_dateM,
		languageId:language
	});
	$('#expeButton').workyear({				//参见工作年份 - 时间控件调用
		yHiddenId:'experience',
		mHiddenId:'experience_month' ,
		close: callBack_expeButton,
		languageId:language
	});
	var Lid = language;
	if(Lid == 1){										//中文数据源
		var data_city = city,							//城市（不含区）
			data_hotCity = hotCity,						//热门城市
			data_CONST_DISTRICT = CONST_DISTRICT;		//区的数据源
	}else{												//英文数据源
		var data_city = city_en,						//城市（不含区）
			data_hotCity = hotCity_en,					//热门城市
			data_CONST_DISTRICT = CONST_DISTRICT_en;	//区的数据源
	}
	var checkCityData = function(Cid){					//遍历城市数据源，查找id相应的city，返回city的value
		if(Cid == 480){
			if(Lid == 1){
				return "海外";
			}else{
				return "OVERSEAS";
			}
		}else{
			for(var i = 0; i < data_city.length; i++){
				for(var j = 0; j < data_city[i].sub.length; j++){
					if(data_city[i].sub[j].id == Cid){
						return data_city[i].sub[j].value;
					}
					if(data_city[i].sub[j].sub){
						for(var k = 0; k < data_city[i].sub[j].sub.length; k++){
							if(data_city[i].sub[j].sub[k].id == Cid){
								return data_city[i].sub[j].sub[k].value;
							}
						}
					}
				}
			}
		}
		alert("This City ID undefined");
	};
	var checkDistrictData = function(Did){				//遍历区数据源，查找id相应的区，返回：城市名 + "-" + 区名
		for(var i = 0; i < data_CONST_DISTRICT.length; i++){
			if(data_CONST_DISTRICT[i].sub){
				for(var j = 0; j < data_CONST_DISTRICT[i].sub.length; j++){
					if(data_CONST_DISTRICT[i].sub[j].id == Did){
						var v = data_CONST_DISTRICT[i].value + "-" + data_CONST_DISTRICT[i].sub[j].value;
						return v;
					}
				}
			}
		}
		alert("This District ID undefined");
	}
	var init = function(){
		(function() {		//参加工作年份初始化
			if($("#expeButton").length > 0){		
				var a = $("#expeButton"),
					b = a.next(),			//年的存储域
					c = b.next(),			//月的存储域
					bv = b.val(),
					cv = c.val(),
					v;
				if(bv && cv){
					if(Lid == 1){
						if(bv=="0"){
							v = "无工作经验";
						}else if(bv == "2003"){
							v = "2003或更早";
						}else{
							v= bv + "年" + cv + "月";
						}						
					}else{
						if(bv=="0"){
							v = "Inexperienced";
						}else if(bv == "2003"){
							v = "2003 or Prior";
						}else{
							v = bv + "." + cv;
						}
						
					}
					a.val(v);
				};
			};
		})();
		(function() {		//户口所在地初始化
			if($("#hukou_selete").length > 0){		
				var a = $("#hukou_selete"),
					b = a.next(),			//省存储域
					c = b.next(),			//市存储域
					bv = b.val(),
					cv = c.val();
				if(bv && cv){
					if(bv == cv){
						var v = checkCityData(bv);
					}else{
						var v = checkCityData(cv);
					}
					a.val(v);
				};
			};
		})();
		(function() {		//现居住城市初始化
			if($("#hukou_pp").length > 0){		
				var a = $("#hukou_pp"),
					b = a.next(),			//省存储域
					c = b.next(),			//市存储域
					d = c.next(),
					bv = b.val(),
					cv = c.val(),
					dv = d.val();
				if(bv && cv){
					if(dv && dv != '0'){
						var v = checkDistrictData(dv);
					}else{
						if(bv == cv){
							var v = checkCityData(bv);
						}else{
							var v = checkCityData(cv);
						}
					}
					a.val(v);
				};
			};
		})();
	}();
});
